<template>
  <MyDrawer ref="myRef" title="意见反馈" :disabled="false" @submit="submit">
    <el-form :model="drawerProps.row" label-width="120" ref="formRef">
      <el-form-item label="反馈内容">
        <el-input
          type="textarea"
          maxlength="1000"
          :show-word-limit="true"
          v-model="drawerProps.row.cont"
          :input-style="{ height: '500px' }"
        ></el-input>
      </el-form-item>
    </el-form>
  </MyDrawer>
</template>

<script setup lang="ts">
import MyDrawer from "@/components/MyDrawer/index.vue";
import { ElMessage, FormInstance } from "element-plus";
import { ref } from "vue";

const myRef = ref<InstanceType<typeof MyDrawer> | null>();

interface DrawerProps {
  row: any;
  api?: (params: any) => Promise<any>;
  getTable?: () => Promise<any>;
}

const initData: any = {
  cont: ""
};

const drawerProps = ref<DrawerProps>(JSON.parse(JSON.stringify(initData)));

const acceptParams = (params: any) => {
  drawerProps.value = params;
  myRef.value?.acceptParams();
};

const formRef = ref<FormInstance>();

const submit = () => {
  if (!formRef.value) return;
  formRef.value.validate(async valid => {
    if (!valid) return;
    try {
      await drawerProps.value.api!(drawerProps.value.row);
      ElMessage.success("成功");
      await drawerProps.value.getTable!();
      myRef.value?.close();
    } catch (error) {}
  });
};

defineExpose({ acceptParams });
</script>

<style></style>
